package com.ywjg.serviceimp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.ywjg.dao.GoodCommentDao;
import com.ywjg.dao.GoodToOrderDao;
import com.ywjg.model.GoodComment;
import com.ywjg.model.GoodToOrder;
import com.ywjg.service.IGoodCommentService;
@Service
public class GoodCommentService implements IGoodCommentService {

	@Resource
	GoodToOrderDao goodToOrderDao;
	@Resource
	GoodCommentDao goodCommentDao;
	
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodCommentService#getGoodComment(java.lang.Integer)
	 */
	public GoodComment getGoodComment(Integer good_to_order_id) {
		return goodCommentDao.findBygoodToOrderId(good_to_order_id);
	}

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodCommentService#deleteOneGoodComment(java.lang.Integer)
	 */
	public void deleteOneGoodComment(Integer goodCommentId) {

	}

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodCommentService#getShouldComment(java.lang.Integer)
	 */
	public List<GoodToOrder> getShouldComment(Integer user_id) {
		return goodToOrderDao.findByIsReciveAndUserIdAndIsComment(1, user_id,0);
	}
	
	
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodCommentService#createComment(com.ywjg.model.GoodComment)
	 */
	public GoodComment createComment(GoodComment goodComment) {
		return goodCommentDao.save(goodComment);
	}
	
	
	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodCommentService#getGoodCommentByGoodId(java.lang.Integer, int, int)
	 */
	public List<GoodComment> getGoodCommentByGoodId(Integer id,int page,int size) {
		Pageable pageable = new PageRequest(page, size, new Sort(Direction.DESC, "timestamp"));
		return goodCommentDao.findBygoodId(id, pageable);
	}

	

	
}